home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / WebsiteX5 / wsx5_ev_demo.exe / {app} / Res / x5cartengine.js < prev    next >
Encoding:
Text File  |  2011-07-23  |  49.0 KB  |  1,045 lines

  1. $.extend(x5engine.imCart, {
  2.  
  3.     _restoreSpecialChars: function (str) {
  4.         return str.replace(/\{1\}/g, "'").replace(/\{2\}/g, "\"").replace(/\{3\}/g, "\\").replace(/\{4\}/g, "<").replace(/\{5\}/g, ">")
  5.     },
  6.     
  7.     // Test if cookies are working in the current browser
  8.     _testCookie: function () {
  9.         $.imCookie("imCookieTest", "test_content");
  10.         if ($.imCookie("imCookieTest") == "test_content") return true;
  11.         return false;
  12.     },
  13.  
  14.     // Get the product array from cookie
  15.     _getCart: function () {
  16.         try {
  17.             if ($.imCookie(x5engine.imCart.costants.COOKIE_NAME, null, { path: '/' }) != null)
  18.                 return $.parseJSON($.imCookie(x5engine.imCart.costants.COOKIE_NAME, null, { path: '/' }));
  19.             else
  20.                 return [];
  21.         } catch (e) {
  22.             $.imCookie(x5engine.imCart.costants.COOKIE_NAME, {}, { path: '/' });
  23.             return [];
  24.         }
  25.     },
  26.  
  27.     // Save the product array to the cookie
  28.     _setCart: function (products) {
  29.         if (!x5engine.imCart._testCookie()) {
  30.             alert(x5engine.l10n.getLocalization("cart_err_cookie"));
  31.             return false;
  32.         }
  33.  
  34.         var json = [];
  35.         for (var i = 0, j = 0; i < products.length; i++)
  36.         if (products[i] != null) {
  37.             json[j] = "{\"id\": \"" + products[i].id + "\", \"quantity\": " + products[i].quantity + ", \"option\": \"" + products[i].option + "\"}";
  38.             j++;
  39.         }
  40.         json = json.join(",");
  41.         json = "[" + json + "]";
  42.  
  43.         $.imCookie(x5engine.imCart.costants.COOKIE_NAME, json, { path: '/' });
  44.     },
  45.  
  46.     // Save the form data in a cookie
  47.     _setFormData: function (post) {
  48.         var json;
  49.         for (var i = 0; i < post.length; i++) {
  50.             post[i] = "{\"id\": \"" + post[i].id + "\", \"val\": \"" + post[i].val + "\"}";
  51.         }
  52.         json = "[" + post.join(",") + "]";
  53.         $.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME, json);
  54.     },
  55.  
  56.     // Get the form data from the cookie
  57.     _getFormData: function () {
  58.         try {
  59.             return $.parseJSON($.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME));
  60.         } catch (e) {
  61.             $.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME, {});
  62.             return null;
  63.         }
  64.     },
  65.  
  66.     // Set the currency format
  67.     _setCurrency: function (n, format, currency) {
  68.         var decsep = "";
  69.         var thsep = "";
  70.         var integer;
  71.         var decimal = "";
  72.         currency = currency || x5engine.imCart.settings.currency;
  73.         if (format == null) format = x5engine.imCart.settings.currency_format;
  74.         var value = "";
  75.         var int_value = parseInt(n.toString());
  76.         var dec_value = n - int_value;
  77.  
  78.         // Find the decimal separator
  79.         decsep = Math.max(format.lastIndexOf("."), format.lastIndexOf(","));
  80.         thsep = Math.min(format.indexOf("."), format.indexOf(","));
  81.         if (thsep == -1 && format.indexOf(".") != -1) thsep = format.indexOf(".");
  82.         if (thsep == -1 && format.indexOf(",") != -1) thsep = format.indexOf(",");
  83.  
  84.         if (decsep != -1) {
  85.             integer = format.substr(0, decsep);
  86.             decimal = format.substr(decsep + 1);
  87.         } else
  88.         integer = format;
  89.  
  90.         if (decsep != thsep && thsep != -1) thsep = format.charAt(thsep);
  91.         else
  92.         thsep = "";
  93.         if (decsep == -1) decsep = "";
  94.         else decsep = format.charAt(decsep);
  95.  
  96.         // Format the int part
  97.         int_value += "";
  98.         for (var i = 0; i < Math.max(integer.length, int_value.length); i++) {
  99.             if (i % 3 == 0 && i != 0 && (int_value.length - i > 0 || integer.charAt(integer.length - 2 - i) == "@")) value = thsep + value;
  100.             if (int_value.length - 1 - i >= 0) value = int_value.charAt(int_value.length - 1 - i) + value;
  101.             else if (integer.charAt(integer.length - 1 - i) == "@") value = "0" + value;
  102.         }
  103.  
  104.         // Set the precision
  105.         var counter = 0;
  106.         for (var i = 0; i < decimal.length; i++)
  107.             if (decimal.charAt(i) == '@') 
  108.                 counter++;
  109.  
  110.         if (counter == 0 && dec_value > 0) {
  111.             counter = 2;
  112.             decimal = "@@";
  113.         }            
  114.                 
  115.         dec_value = Math.round(dec_value*Math.pow(10,counter))/Math.pow(10,counter);
  116.         
  117.         // Format the decimal part
  118.         dec_value = dec_value.toString();
  119.         dec_value = dec_value.substr(dec_value.indexOf(".") + 1);
  120.         decimal = decimal.replace("[C]", "");
  121.  
  122.         for (var i = 0; i < decimal.length; i++) {
  123.             if (i == 0) value += decsep.toString();
  124.             if (dec_value.length > i) value += dec_value.charAt(i).toString();
  125.             else if (decimal.charAt(i) == "@") value += "0";
  126.         }    
  127.  
  128.         // Add the currency symbol
  129.         if (format.indexOf("[C]") == 0) value = currency + value;
  130.         else if (format.indexOf("[C]") != -1) value += currency;
  131.  
  132.         return value;
  133.     },
  134.  
  135.     // Get the value of the key
  136.     _getValueFromKey: function (key, array) {
  137.         var value;
  138.         if (array["0"] == null) 
  139.             value = 0;
  140.         else
  141.             value = array["0"];
  142.             
  143.         if (key * 1 > 0) 
  144.             for (var property in array)
  145.                 if (property * 1 <= key * 1) 
  146.                     value = array[property];
  147.  
  148.         return value;
  149.     },
  150.  
  151.     // Get the shipping price
  152.     _getShippingPrice: function (shipping, subtotal, total_quantity, total_weight) {
  153.         if (shipping.price != null) {
  154.             switch (shipping.type) {
  155.                 case "WEIGHT":
  156.                     price = x5engine.imCart._getValueFromKey(total_weight, shipping.price);
  157.                     break;
  158.                 case "QUANTITY":
  159.                     price = x5engine.imCart._getValueFromKey(total_quantity, shipping.price);
  160.                     break;
  161.                 case "AMOUNT":
  162.                     price = x5engine.imCart._getValueFromKey(subtotal, shipping.price);
  163.                     break;
  164.                 default:
  165.                     price = shipping.price;
  166.                     break;
  167.             }
  168.             if (shipping.vat != null) 
  169.                 price += price * shipping.vat;
  170.             return price;
  171.         }
  172.  
  173.         return 0;
  174.     },
  175.  
  176.     // Set the payment type
  177.     _setPayment: function (n) {
  178.         x5engine.imCart.payment_type = n;
  179.     },
  180.  
  181.     // Get the payment type
  182.     _getPayment: function () {
  183.         return x5engine.imCart.payment_type;
  184.     },
  185.  
  186.     // Set the shipping type
  187.     _setShipping: function (n) {
  188.         x5engine.imCart.shipping_type = n;
  189.     },
  190.  
  191.     // Get the shipping type
  192.     _getShipping: function () {
  193.         return x5engine.imCart.shipping_type;
  194.     },
  195.  
  196.     // Empty the cookie and reset the cart
  197.     _realEmptyCart: function () {
  198.         x5engine.imCart._setCart([]);
  199.         x5engine.imCart.updateWidget();
  200.         if ($("#imInputTotalPrice").length > 0) x5engine.imCart.showCart();
  201.     },
  202.  
  203.     // Create a string ready to be used in an HTML/JS string
  204.     _htmlOutput: function (str) {
  205.         return str.replace(/\"/g, "''").replace(/\</g, "<").replace(/\>/g, ">");
  206.     },
  207.     
  208.     // Create the order number
  209.     _createOrderNo: function (format) {
  210.         if (format == null) format = x5engine.imCart.settings.order_no_format;
  211.         var date = new Date();
  212.         var day = date.getDate();
  213.         var month = date.getMonth() + 1;
  214.         var shortYear = date.getYear().toString();
  215.         shortYear = shortYear.substring(shortYear.length - 2);
  216.         if (parseInt(day) < 10) day = "0" + day;
  217.         if (parseInt(month) < 10) month = "0" + month;
  218.  
  219.         format = format.replace(/\[dd\]/g, day);
  220.         format = format.replace(/\[mm\]/g, month);
  221.         format = format.replace(/\[yy\]/g, shortYear);
  222.         format = format.replace(/\[yyyy\]/g, date.getFullYear());
  223.         while (format.match(/\[A-Z\]/)) format = format.replace(/\[A-Z\]/, String.fromCharCode(Math.round(Math.random() * 25 + 65)));
  224.         while (format.match(/\[a-z\]/)) format = format.replace(/\[a-z\]/, String.fromCharCode(Math.round(Math.random() * 25 + 97)));
  225.         while (format.match(/\[0-9\]/)) format = format.replace(/\[0-9\]/g, Math.round(Math.random() * 9));
  226.  
  227.         return format;
  228.     },
  229.     
  230.     // Create the correct HTML code for operational purposes
  231.     _createPaymentHtml: function (paymentHtml) {
  232.     
  233.         // Replaces the keywords
  234.         if (x5engine.imCart.email_data.order_no == null || x5engine.imCart.email_data.order_no == "")
  235.             x5engine.imCart.email_data.order_no = x5engine.imCart._createOrderNo();
  236.         paymentHtml = paymentHtml.replace(/\[ORDER_NO\]/g, x5engine.imCart.email_data.order_no);
  237.         paymentHtml = paymentHtml.replace(/\[QUANTITY\]/g, x5engine.imCart.email_data.total_quantity);
  238.         paymentHtml = paymentHtml.replace(/\[WEIGHT\]/g, x5engine.imCart.email_data.total_weight);
  239.         var price = x5engine.imCart.email_data.clear_total;
  240.         // Format the price
  241.         var format = x5engine.imCart.settings.cart_price;
  242.         if (format.multiplier != null) price *= format.multiplier;
  243.         price = x5engine.imCart._setCurrency(price.toString(), format.format);
  244.         paymentHtml = paymentHtml.replace(/\[PRICE\]/g, price);
  245.         while (paymentHtml.match(/\[PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/)) {
  246.             price = x5engine.imCart.email_data.clear_total;
  247.             price *= parseInt(RegExp.$1);
  248.             price = x5engine.imCart._setCurrency(price.toString(), RegExp.$2);
  249.             paymentHtml = paymentHtml.replace(/\[PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/, price);
  250.         }
  251.         
  252.         //Customer data fields
  253.         post = x5engine.imCart.email_data.form;
  254.         if (post != null && post["imCartName_shipping"] != null && post["imCartName_shipping"] != "") {
  255.             paymentHtml = paymentHtml.replace(/\[FIRST_NAME\]/g, ((post["imCartName_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartName_shipping"].imValue) : ""));
  256.             paymentHtml = paymentHtml.replace(/\[LAST_NAME\]/g, ((post["imCartLastName_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartLastName_shipping"].imValue) : ""));
  257.             paymentHtml = paymentHtml.replace(/\[ADDRESS1\]/g, ((post["imCartAddress1_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress1_shipping"].imValue) : ""));
  258.             paymentHtml = paymentHtml.replace(/\[ADDRESS2\]/g, ((post["imCartAddress2_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress2_shipping"].imValue) : ""));
  259.             paymentHtml = paymentHtml.replace(/\[CITY\]/g, ((post["imCartCity_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartCity_shipping"].imValue) : ""));
  260.             paymentHtml = paymentHtml.replace(/\[STATE\]/g, ((post["imCartStateRegion_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartStateRegion_shipping"].imValue) : ""));
  261.             paymentHtml = paymentHtml.replace(/\[COUNTRY\]/g, ((post["imCartCountry_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartCountry_shipping"].imValue) : ""));
  262.             paymentHtml = paymentHtml.replace(/\[ZIP\]/g, ((post["imCartZipPostalCode_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartZipPostalCode_shipping"].imValue) : ""));
  263.             paymentHtml = paymentHtml.replace(/\[EMAIL\]/g, ((post["imCartEmail_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartEmail_shipping"].imValue) : ""));
  264.         } else if (post != null) {
  265.             paymentHtml = paymentHtml.replace(/\[FIRST_NAME\]/g, ((post["imCartName"] != null) ? x5engine.imCart._htmlOutput(post["imCartName"].imValue) : ""));
  266.             paymentHtml = paymentHtml.replace(/\[LAST_NAME\]/g, ((post["imCartLastName"] != null) ? x5engine.imCart._htmlOutput(post["imCartLastName"].imValue) : ""));
  267.             paymentHtml = paymentHtml.replace(/\[ADDRESS1\]/g, ((post["imCartAddress1"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress1"].imValue) : ""));
  268.             paymentHtml = paymentHtml.replace(/\[ADDRESS2\]/g, ((post["imCartAddress2"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress2"].imValue) : ""));
  269.             paymentHtml = paymentHtml.replace(/\[CITY\]/g, ((post["imCartCity"] != null) ? x5engine.imCart._htmlOutput(post["imCartCity"].imValue) : ""));
  270.             paymentHtml = paymentHtml.replace(/\[STATE\]/g, ((post["imCartStateRegion"] != null) ? x5engine.imCart._htmlOutput(post["imCartStateRegion"].imValue) : ""));
  271.             paymentHtml = paymentHtml.replace(/\[COUNTRY\]/g, ((post["imCartCountry"] != null) ? x5engine.imCart._htmlOutput(post["imCartCountry"].imValue) : ""));
  272.             paymentHtml = paymentHtml.replace(/\[ZIP\]/g, ((post["imCartZipPostalCode"] != null) ? x5engine.imCart._htmlOutput(post["imCartZipPostalCode"].imValue) : ""));
  273.             paymentHtml = paymentHtml.replace(/\[EMAIL\]/g, ((post["imCartEmail"] != null) ? x5engine.imCart._htmlOutput(post["imCartEmail"].imValue) : ""));
  274.         }
  275.  
  276.         return paymentHtml;
  277.     },
  278.  
  279.     _updateOption: function (id, old_option, new_option, quantity, obj) {
  280.         x5engine.imCart.addProduct(id, 0, old_option, true, false);
  281.         x5engine.imCart.addProduct(id, quantity, new_option);
  282.         x5engine.imCart.showCart($(obj).attr("id"), 1);
  283.     },
  284.     
  285.     cartPage: function () {
  286.         var category = x5engine.utils.getParam("category");
  287.         if (category != null && category != "")
  288.             x5engine.imCart.showCategory(x5engine.utils.getParam("category"));
  289.         else
  290.             x5engine.imCart.showCart();
  291.     },
  292.     
  293.     // Save the current page and go to the cart
  294.     gotoCart: function (in_cart) {
  295.         if (typeof in_cart == "string") {
  296.             $.imCookie("imShopPage", window.location.href, { path: '/' });
  297.             location.href = in_cart + "cart/index.html";
  298.             return true;
  299.         } else {
  300.             if (in_cart == null)
  301.                 in_cart = false;
  302.             if (!in_cart) {
  303.                 $.imCookie("imShopPage", window.location.href, { path: '/' });
  304.                 location.href = "cart/index.html";
  305.             }
  306.             else {            
  307.                 location.href = "index.html";
  308.             }
  309.         }
  310.         
  311.         return false;
  312.     },
  313.     
  314.     gotoCategory: function (id) {
  315.         $.imCookie("imShopPage", window.location.href);
  316.         location.href = "cart/index.html?category=" + id;
  317.     },
  318.  
  319.     // Continue shopping button
  320.     continueShopping: function () {
  321.         var oldPage = $.imCookie("imShopPage", null, { path: '/' });
  322.         if (oldPage != null) {
  323.             window.location.href = oldPage;
  324.         }
  325.         else
  326.             window.location.href = x5engine.imCart.settings.continue_shopping_page;
  327.     },
  328.  
  329.     // Add a product quantity to the cart
  330.     // If force is true, quantity overrides the actual quantity in the cart. If force is false the quantity is added to the existing one 
  331.     addProduct: function (id, quantity, option, force, message) {
  332.         if (message == null) message = true;
  333.         if (quantity == null) quantity = 1;
  334.         if (force == null) force = false;
  335.         if (option == null) option = "null";
  336.  
  337.         if (x5engine.imCart.products[id].min_quantity != null && quantity < x5engine.imCart.products[id].min_quantity && quantity != 0) {
  338.             alert((x5engine.l10n.getLocalization("cart_err_quantity")).replace("[QUANTITY]", x5engine.imCart.products[id].min_quantity));
  339.             return false;
  340.         }
  341.  
  342.         var products = x5engine.imCart._getCart();
  343.         if (products == null && quantity > 0) {
  344.             x5engine.imCart._setCart([{
  345.                 "id": id,
  346.                 "quantity": quantity,
  347.                 "option": escape(option)
  348.             }]);
  349.         } else {
  350.             var found = false;
  351.             for (var i = 0; i < products.length; i++) {
  352.                 if (products[i].id == id && unescape(products[i].option) == unescape(option)) {
  353.                     found = true;
  354.                     if (!force) 
  355.                         products[i].quantity = products[i].quantity * 1 + quantity * 1;
  356.                     else {
  357.                         if (quantity > 0) products[i].quantity = quantity * 1;
  358.                         else if (message && confirm(x5engine.l10n.getLocalization("cart_remove_q"))) products[i] = null;
  359.                         else if (!message) products[i] = null;
  360.                     }
  361.                 }
  362.             }
  363.             
  364.             if (!found && quantity > 0) products[products.length] = {
  365.                 "id": id,
  366.                 "quantity": quantity,
  367.                 "option": escape(option)
  368.             };
  369.  
  370.             x5engine.imCart._setCart(products);
  371.         }
  372.     },
  373.  
  374.     // Add a product to the cart
  375.     addToCart: function (id, quantity, in_cart, option) {
  376.         var product = x5engine.imCart.products[id];
  377.         if (quantity == null) 
  378.             quantity = $("#" + x5engine.imCart.costants.QUANT_FIELD_NAME.replace("{id}", id)).val();
  379.         if (quantity == null) 
  380.             quantity = 1;
  381.         if (option == null) {
  382.             if ($("#" + x5engine.imCart.costants.OPT_FIELD_NAME.replace("{id}", id)).length > 0) 
  383.                 option = $("#" + x5engine.imCart.costants.OPT_FIELD_NAME.replace("{id}", id)).val();
  384.             else
  385.                 option = "null";
  386.         }
  387.         
  388.         if (in_cart == null) 
  389.             in_cart = false;
  390.  
  391.         if (/^[0-9]+$/.test(quantity) == false) {
  392.             alert(x5engine.l10n.getLocalization("cart_err_qty"));
  393.             return false;
  394.         }
  395.  
  396.         x5engine.imCart.addProduct(id, quantity, option);
  397.         x5engine.imCart.updateWidget();
  398.         x5engine.imCart.gotoCart(in_cart);
  399.     },
  400.  
  401.     // Remove a product from the cart
  402.     removeFromCart: function (id, option, obj) {
  403.         x5engine.imCart.addProduct(id, 0, option, true);
  404.         x5engine.imCart.updateWidget();
  405.         x5engine.imCart.showCart(obj, 1);
  406.     },
  407.  
  408.     // Update the quantity of a product in the cart
  409.     updateCart: function (id, obj, updateScreen) {
  410.         if (updateScreen == null) 
  411.             updateScreen = false;
  412.         var quantity = $(obj).val();
  413.         if (/^[0-9]+$/.test(quantity) == false) {
  414.             alert(x5engine.l10n.getLocalization("cart_err_qty"));
  415.             return false;
  416.         }
  417.         var products = x5engine.imCart._getCart();
  418.         var option = "null";
  419.         var total_quantity = 0;
  420.         var total_weight = 0;
  421.         
  422.         for (var i = 0; i < products.length; i++) {
  423.             if (products[i].id == id) {
  424.                 option = products[i].option;
  425.                 total_weight += x5engine.imCart.products[id].weight * quantity;
  426.                 total_quantity += quantity;
  427.             }
  428.             else {
  429.                 total_weight += x5engine.imCart.products[id].weight * products[i].quantity;
  430.                 total_quantity += products[i].quantity;
  431.             }
  432.         }
  433.  
  434.         x5engine.imCart.addProduct(id, quantity, option, true);
  435.         x5engine.imCart.updateWidget();
  436.         if (updateScreen) 
  437.             x5engine.imCart.showCart(null, 0);
  438.         
  439.         x5engine.imCart.updateTotalPrice(total_quantity, total_weight);
  440.     },
  441.  
  442.     // Update the widget
  443.     updateWidget: function () {
  444.         var products = x5engine.imCart._getCart();
  445.         var sum = 0;
  446.         var total_vat = 0;
  447.         var total = 0;
  448.         
  449.         $(".widget_quantity_total").each(function () {
  450.             if (products != null) {
  451.                 for (var i = 0; i < products.length; i++) {
  452.                     if (x5engine.imCart.products[products[i].id] != null)
  453.                         sum += products[i].quantity;
  454.                 }
  455.             }
  456.             $(this).html(sum);
  457.         });
  458.         $(".widget_amount_total").each(function () {
  459.             if (products != null) {
  460.                 for (var i = 0; i < products.length; i++) {
  461.                     var id = products[i].id;
  462.                     if (x5engine.imCart.products[id] != null) {
  463.                         var quantity = products[i].quantity;
  464.                         var option = products[i].option;
  465.                         var discounts = x5engine.imCart.products[id].discounts;
  466.                         var weight = x5engine.imCart.products[id].weight;
  467.                         if (weight == null) weight = 0;
  468.                         var discount = 0;
  469.                         var subtot = 0;
  470.                         var vat;
  471.  
  472.                         if (x5engine.imCart.products[id].vat != null) 
  473.                             vat = x5engine.imCart.products[id].vat;
  474.                         else if (x5engine.imCart.settings.vat != null) 
  475.                             vat = x5engine.imCart.settings.vat;
  476.                         else
  477.                             vat = 0;
  478.  
  479.                         if (discounts != null) 
  480.                             discount = x5engine.imCart._getValueFromKey(quantity, discounts);
  481.                             
  482.                         subtot = quantity * x5engine.imCart.products[id].price;
  483.                         subtot -= (subtot * discount);
  484.  
  485.                         total_vat += subtot + subtot * vat;
  486.                     }
  487.                 }
  488.                 sum = total_vat;
  489.             }            
  490.             $(this).html(x5engine.imCart._setCurrency(sum));
  491.         });    
  492.     },
  493.  
  494.     // Empty the cart
  495.     emptyCart: function (getConfirmation) {
  496.         if (getConfirmation == null) getConfirmation = true;
  497.         if (getConfirmation == true) {
  498.             if (confirm(x5engine.l10n.getLocalization("cart_empty"))) 
  499.                 x5engine.imCart._realEmptyCart();
  500.         } else
  501.             x5engine.imCart._realEmptyCart();
  502.         return false;
  503.     },
  504.  
  505.     // Show a category
  506.     showCategory: function (id, obj) {
  507.         obj = obj || "#imCartContainer";
  508.         $(obj).empty().prepend("<h2 id=\"imPgTitle\">" + x5engine.l10n.getLocalization('cart_step1') + "</h2>\n<div style=\"height: 15px;\"> </div>" + x5engine.l10n.getLocalization('cart_step1_descr') + "<br /><br /><br />");
  509.         var html = "<table id=\"imCartProductsTable\"><tr class=\"imCartHeader\">";
  510.         html += "<td>" + x5engine.l10n.getLocalization("cart_descr") + "</td>";
  511.         html += "<td>" + x5engine.l10n.getLocalization("cart_opt") + "</td>";
  512.         html += "<td>" + x5engine.l10n.getLocalization("cart_price") + "</td>";
  513.         if (!x5engine.imCart.settings.vatincluded)
  514.             html += "<td>" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
  515.         html += "<td>" + x5engine.l10n.getLocalization("cart_qty") + "</td>";
  516.         html += "</tr>";
  517.         var str_eval = "";
  518.         for (var pid in x5engine.imCart.products) {
  519.             var product = x5engine.imCart.products[pid];
  520.             if (product.category == id) {
  521.                 html += "<tr><td><b>" + product.name + "</b><br />" + product.description + "</td>";
  522.                 html += "<td>";
  523.                 if (product.options != null && product.options.length > 0) {
  524.                     html += "<select id=\"product_" + pid + "_opt\">";
  525.                     for (var option in product.options)
  526.                     html += "<option value=\"" + product.options[option] + "\">" + x5engine.imCart._restoreSpecialChars(unescape(product.options[option])) + "</option>";
  527.                     html += "</select>";
  528.                 }
  529.                 html += "</td>";
  530.                 html += "<td style=\"text-align: right;\">" + x5engine.imCart._setCurrency(product.price) + "</td>";
  531.                 if (!x5engine.imCart.settings.vatincluded)
  532.                     html += "<td style=\"text-align: right;\">" + ((product.vat != null && product.vat > 0) ? (product.vat * 100).toFixed(2) + "%" : " - ") + "</td>";
  533.                 html += "<td style=\"text-align: right;\"><input type=\"text\" value=\"1\" id=\"product_" + pid + "_qty\" size=\"3\" style=\"text-align: right\"/>";
  534.                 html += "<img id=\"buy_" + pid + "\" style=\"cursor: pointer; vertical-align: middle; margin-left: 5px;\" src=\"images/cart-add.gif\" alt=\"" + x5engine.l10n.getLocalization("cart_add") + "\" title=\"" + x5engine.l10n.getLocalization("cart_add") + "\" /></td>";
  535.                 str_eval += "$('#buy_" + pid + "').unbind('click').click(function () { x5engine.imCart.addToCart('" + pid + "', null, true); });";
  536.                 html += "</tr>";
  537.             }
  538.         }
  539.  
  540.         html += "</table>";
  541.         html += "<div style=\"text-align: center; margin-top: 20px;\">";
  542.         html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_continue_shopping") + "\" style=\"margin-right: 5px;\" />";
  543.         html += "<input type=\"button\" id=\"imCartButtonNext\" value=\"" + x5engine.l10n.getLocalization("cart_goshop") + "\" style=\"margin-right: 5px;\" />";
  544.         html += "</div>";
  545.  
  546.         $(obj).append(html);
  547.         eval(str_eval);
  548.         $("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping);
  549.         $("#imCartButtonNext").unbind("click").click(function () { x5engine.imCart.showCart(); });
  550.     },
  551.  
  552.     // Show the cart
  553.     showCart: function (obj, time) {
  554.         var email_data = {};
  555.         var str_eval = "";
  556.  
  557.         $(".imTip").fadeOut(100, function () {
  558.             $(".imTip").remove();
  559.         });
  560.  
  561.         obj = obj || "#imCartContainer";
  562.         obj = $(obj);
  563.         if (time == null) time = 100;
  564.  
  565.         var products = x5engine.imCart._getCart();
  566.         var filtered_products = new Array();
  567.         // Filter the products (if the cookie contains products not in the cart anymore)
  568.         for (var i = 0; i < products.length; i++) {
  569.             if (x5engine.imCart.products[products[i].id] != null)
  570.                 filtered_products[filtered_products.length] = products[i];
  571.         }
  572.         products = filtered_products;
  573.         
  574.         if (products != null && products.length > 0) {
  575.             obj.fadeOut(time, function () {
  576.                 obj.empty().prepend("<h2 id=\"imPgTitle\">" + x5engine.l10n.getLocalization('cart_step2') + "</h2>\n<div style=\"height: 15px;\"> </div>");
  577.                 
  578.                 var html = x5engine.l10n.getLocalization('cart_step2_cartlist') + "<br /><br />";
  579.                 
  580.                 // Products
  581.                 html += "<table id=\"imCartProductsTable\"><tr class=\"imCartHeader\">";
  582.                 html += "<td>" + x5engine.l10n.getLocalization("cart_descr") + "</td>";
  583.                 html += "<td>" + x5engine.l10n.getLocalization("cart_opt") + "</td>";
  584.                 html += "<td>" + x5engine.l10n.getLocalization("cart_price") + "</td>";
  585.                 if (!x5engine.imCart.settings.vatincluded)
  586.                     html += "<td>" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
  587.                 html += "<td>" + x5engine.l10n.getLocalization("cart_qty") + "</td>";
  588.                 html += "<td>" + x5engine.l10n.getLocalization("cart_subtot") + "</td><td></td></tr>";
  589.                 var total = 0;
  590.                 var total_vat = 0;
  591.                 var shipping_total = 0;
  592.                 var shipping_total_vat = 0;
  593.                 var total_quantity = 0;
  594.                 var total_weight = 0;        
  595.             
  596.                 for (var i = 0; i < products.length; i++) {
  597.                     var id = products[i].id;
  598.                     var quantity = products[i].quantity;
  599.                     var option = products[i].option;
  600.                     var discounts = x5engine.imCart.products[id].discounts;
  601.                     var weight = x5engine.imCart.products[id].weight;
  602.                     if (weight == null) weight = 0;
  603.                     var discount = 0;
  604.                     var subtot = 0;
  605.                     var vat;
  606.  
  607.                     if (x5engine.imCart.products[id].vat != null) 
  608.                         vat = x5engine.imCart.products[id].vat;
  609.                     else if (x5engine.imCart.settings.vat != null) 
  610.                         vat = x5engine.imCart.settings.vat;
  611.                     else
  612.                         vat = 0;
  613.  
  614.                     if (discounts != null) 
  615.                         discount = x5engine.imCart._getValueFromKey(quantity, discounts);
  616.  
  617.                     total_weight += weight * quantity;
  618.                     total_quantity += quantity;
  619.                     subtot = quantity * x5engine.imCart.products[id].price;
  620.                     subtot -= (subtot * discount);
  621.  
  622.                     total += subtot;
  623.                     total_vat += subtot + subtot * vat;
  624.  
  625.                     var cart_p = x5engine.imCart.products[id];
  626.                     email_data[id + "_" + option] = {
  627.                         id_user: cart_p.id_user,
  628.                         name: cart_p.name,
  629.                         description: cart_p.description,
  630.                         single_price: x5engine.imCart._setCurrency(x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount),
  631.                         price: x5engine.imCart._setCurrency(subtot),
  632.                         price_vat: x5engine.imCart._setCurrency(subtot + subtot * vat),
  633.                         option: option,
  634.                         quantity: quantity,
  635.                         vat: vat,
  636.                         vat_f: x5engine.imCart._setCurrency(vat * (x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount))
  637.                     };
  638.  
  639.                     html += "<tr><td>" + x5engine.imCart.products[id].id_user + (x5engine.imCart.products[id].description != "" ? " - " + x5engine.imCart.products[id].description : "") + "</td>";
  640.                     html += "<td>";
  641.                     if (option != "null") {
  642.                         var freeid = "product_" + id + "_" + x5engine.utils.imHash(option) + "_opt";
  643.                         html += "<select id=\"" + freeid + "\">";
  644.                         for (var j = 0; j < x5engine.imCart.products[id].options.length; j++) {
  645.                             html += "<option value=\"" + x5engine.imCart.products[id].options[j] + "\" " + ((x5engine.imCart.products[id].options[j] == unescape(option)) ? "selected" : "") + ">" + x5engine.imCart._restoreSpecialChars(unescape(x5engine.imCart.products[id].options[j])) + "</option>";
  646.                             str_eval += "$('#" + freeid + "').unbind('change').change(function () {x5engine.imCart._updateOption('" + id + "', '" + option + "', $('#" + freeid + "').val() , " + quantity + ", '" + $(obj).attr("id") + "')});";
  647.                         }
  648.                         html += "</select>";
  649.                     }
  650.                     html += "</td>";
  651.                     html += "<td style=\"text-align: right;\">" + x5engine.imCart._setCurrency(x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount) + "</td>";
  652.                     if (!x5engine.imCart.settings.vatincluded)
  653.                         html += "<td style=\"text-align: right;\">" + ((vat) ? (vat * 100).toFixed(2) + "%" : "-") + "</td>";
  654.                     html += "<td style=\"text-align: right;\"><input style=\"text-align: right;\" id=\"qty_product_" + i + "\" type=\"text\" value=\"" + quantity + "\" size=\"2\"></td>";
  655.                     str_eval += "$('#qty_product_" + i + "').unbind('change').change(function () {x5engine.imCart.updateCart('" + id + "', this, true);});";
  656.                     html += "<td style=\"text-align: right;\">" + x5engine.imCart._setCurrency(subtot + subtot * vat) + "</td>"; 
  657.                     html += "<td style=\"text-align: center\"><img id=\"remove_product_" + i + "\" style=\"vertical-align: middle; cursor: pointer;\" src=\"../cart/images/cart-remove.gif\" alt=\"" + x5engine.l10n.getLocalization("cart_remove") + "\" title=\"" + x5engine.l10n.getLocalization("cart_remove") + "\" /></td></tr>";
  658.                     str_eval += "$('#remove_product_" + i + "').click(function () { return x5engine.imCart.removeFromCart('" + id + "', '" + option + "', '#" + $(obj).attr('id') + "'); });";
  659.                 }
  660.                 
  661.                 x5engine.imCart.product_price_plus_vat = total_vat;
  662.  
  663.                 if (x5engine.imCart.email_data == null) x5engine.imCart.email_data = {};
  664.                 x5engine.imCart.email_data.products = email_data;
  665.  
  666.                 html += "<tr style=\"text-align: right;\"><td style=\"border-width: 0; background-color: transparent;\" colspan=\"4\"></td><td class=\"nostyle\">" + x5engine.l10n.getLocalization("cart_total") + "</td><td class=\"nostyle\">" + x5engine.imCart._setCurrency(total) + "</td></tr>";
  667.                 if (!x5engine.imCart.settings.vatincluded)
  668.                     html += "<tr style=\"text-align: right;\"><td style=\"border-width: 0; background-color: transparent;\" colspan=\"4\"></td><td class=\"nostyle\">" + x5engine.l10n.getLocalization("cart_total_vat") + "</td><td class=\"nostyle\">" + x5engine.imCart._setCurrency(total_vat) + "</td></tr>";
  669.  
  670.                 html += "</table>";
  671.                 html += "<input type=\"hidden\" id=\"imInputTotalPrice\" name=\"imInputTotalPrice\" value=\"" + total_vat + "\"/>";
  672.  
  673.                 // Payment
  674.                 html += "<br />" + x5engine.l10n.getLocalization('cart_step2_shiplist') + "<br /><br /><table id=\"imCartPaymentsTable\">";
  675.                 html += "<tr class=\"imCartHeader\"><td colspan=\"2\">" + x5engine.l10n.getLocalization('cart_payment') + "</td><td>" + x5engine.l10n.getLocalization("cart_price") + "</td></tr>";
  676.                 var payments = x5engine.imCart.payments;
  677.  
  678.                 for (var i = 0; i < payments.length; i++) {
  679.                     var price = payments[i].price || 0;
  680.                     if (payments[i].vat != null) price += price * payments[i].vat;
  681.                     html += "<tr><td style=\"width: 5%\"><input type=\"radio\" name=\"imPaymentType\" value=\"" + i + "\" id=\"cart_payment_" + i + "\" " + ((x5engine.imCart._getPayment() == i && x5engine.imCart.email_data.payment != null) ? "checked" : "") + "/></td><td style=\"width: 80%\"><label for=\"cart_payment_" + i + "\"><b>" + payments[i].name + ":</b> " + payments[i].description + "</label></td><td style=\"width: 15%; text-align: right;\">" + ((price > 0) ? x5engine.imCart._setCurrency(price) : "-") + "</td></tr>";
  682.                     str_eval += "$('#cart_payment_" + i + "').unbind('click').click(function () { x5engine.imCart.updatePayment(" + i + ", " + total_quantity + ", " + total_weight + ")});";
  683.                     if (x5engine.imCart._getPayment() == i) total_vat += price;
  684.                 }
  685.                 html += "</table>";
  686.                 
  687.                 // Shipping
  688.                 html += "<br /><table id=\"imCartShippingsTable\">";
  689.                 html += "<tr class=\"imCartHeader\"><td colspan=\"2\">" + x5engine.l10n.getLocalization('cart_shipping') + "</td><td>" + x5engine.l10n.getLocalization("cart_price") + "</td></tr>";
  690.                 var shippings = x5engine.imCart.shippings;
  691.  
  692.                 for (var i = 0; i < shippings.length; i++) {
  693.                     var price = x5engine.imCart._getShippingPrice(shippings[i], x5engine.imCart.product_price_plus_vat, total_quantity, total_weight);
  694.                     html += "<tr><td style=\"width: 5%\"><input type=\"radio\" name=\"imShippingType\" value=\"" + i + "\" id=\"cart_shipping_" + i + "\" " + ((x5engine.imCart._getShipping() == i && x5engine.imCart.email_data.shipping != null) ? "checked" : "") + "/></td><td style=\"width: 80%\"><label for=\"cart_shipping_" + i + "\"><b>" + shippings[i].name + ":</b> " + shippings[i].description + "</label></td><td style=\"width: 15%; text-align: right;\">" + ((price > 0) ? x5engine.imCart._setCurrency(price) : "-") + "</td></tr>";
  695.                     str_eval += "$('#cart_shipping_" + i + "').unbind('click').click(function () {x5engine.imCart.updateShipping(" + i + ", " + total_quantity + ", " + total_weight + ");});";
  696.                     if (x5engine.imCart._getShipping() == i) 
  697.                         total_vat += price;
  698.                 }
  699.                 html += "</table><br />";
  700.                 
  701.                 // Price summary
  702.                 html += "<div><div id=\"imCartTotalPriceCont\">" + x5engine.l10n.getLocalization('cart_total_price') + ": <span id=\"imDivTotalPrice\">" + x5engine.imCart._setCurrency(total_vat) + "</span></div></div>";
  703.                 
  704.                 // Currency conversion disable
  705.                 if (x5engine.utils.isOnline() && false) {
  706.                     var currencies = x5engine.imCart.settings.currencies;
  707.                     if (currencies != null && currencies.length > 0) {
  708.                         html += "<select id=\"imCurrencyConversion\" style=\"margin-left: 10px\">";
  709.                         str_eval += "$('#imCurrencyConversion').unbind('change').change(function () { x5engine.imCart.currencyConversion(this); });";
  710.                         html += "<option value=\"\">" + x5engine.l10n.getLocalization("cart_currency_conversion") + "</option>";
  711.                         for (i = 0; i < currencies.length; i++) {
  712.                             html += "<option value=\"" + currencies[i].value + "\">" + currencies[i].value + " - " + currencies[i].text + "</option>";
  713.                         }
  714.                         html += "</select><div id=\"currencyConvResult\">Risultato conversione</div>";
  715.                     }
  716.                 }
  717.                 
  718.                 html += "<br /><br /><br />";
  719.                 html += "<div style=\"text-align: center; margin-top: 30px;\">";
  720.                 html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_continue_shopping") + "\" style=\"margin-right: 5px;\" />";
  721.                 html += "<input type=\"button\" id=\"imCartButtonEmpty\" value=\"" + x5engine.l10n.getLocalization("cart_empty_button") + "\" style=\"margin: 0 5px;\" />";
  722.                 html += "<input type=\"button\" id=\"imCartButtonNext\" value=\"" + x5engine.l10n.getLocalization("cart_gonext") + "\" style=\"margin-left: 5px;\"/>";
  723.                 html += "</div>";
  724.             
  725.                 obj.append(html).fadeIn(time);
  726.                 $("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping);
  727.                 $("#imCartButtonEmpty").unbind("click").click(function () { x5engine.imCart.emptyCart(true); });
  728.                 $("#imCartButtonNext").unbind("click").click(function () { x5engine.imCart.showForm('#' + $(obj).attr("id")); });
  729.                 eval(str_eval);
  730.                 $("#imInputTotalPrice").val(total_vat);
  731.             });
  732.         } else {
  733.             obj.fadeOut(time, function () {
  734.                 obj.empty().prepend("<h2 id=\"imPgTitle\">" + x5engine.l10n.getLocalization('cart_step2') + "</h2>\n<div style=\"height: 15px;\"> </div><br />");
  735.                 obj.append("<div style=\"text-align: center; font-weight: bold; font-size: 12px;\">" + x5engine.l10n.getLocalization("cart_err_emptycart") + "</div><br /><br />");
  736.                 obj.append("<div style=\"text-align: center\"><input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_continue_shopping") + "\" style=\"margin-right: 5px;\" /></div>");
  737.                 $("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping);
  738.                 obj.fadeIn(time);
  739.             });
  740.         }
  741.  
  742.         return false;
  743.     },
  744.  
  745.     // Convert currency using Google
  746.     currencyConversion: function (obj) {
  747.         if (obj.selectedIndex != 0) {
  748.             if (x5engine.imCart.email_data.clear_total != null) {
  749.                 $.ajax({
  750.                     url: x5engine.imCart.settings.post_url + "?action=currency&amount=" + x5engine.imCart.email_data.clear_total + "&from=" + x5engine.imCart.settings.currency_id + "&to=" + $(obj).val(),
  751.                     type: "GET",
  752.                     dataType: "json",
  753.                     success: function (data) {
  754.                         $("#currencyConvResult").html(x5engine.imCart._setCurrency(data.value, x5engine.imCart.settings.currency_format, $(obj).val()));
  755.                     },
  756.                     error: function () {
  757.                         $("#currencyConvResult").html(x5engine.l10n.getLocalization("cart_err_currency_conversion"));
  758.                     }
  759.                 });
  760.             } else {
  761.                 obj.selectedIndex = 0;
  762.             }
  763.         } else {
  764.             $("#currencyConvResult").empty();
  765.         }
  766.     },
  767.  
  768.     // Show the user data form
  769.     showForm: function (obj) {
  770.         if (x5engine.imCart._getPayment() == null) {
  771.             alert(x5engine.l10n.getLocalization("cart_err_payment"));
  772.             return false;
  773.         }
  774.         if (x5engine.imCart._getShipping() == null) {
  775.             alert(x5engine.l10n.getLocalization("cart_err_shipping"));
  776.             return false;
  777.         }
  778.         
  779.         if (x5engine.imCart.settings.minimum_amount > 0 &&     $("#imInputTotalPrice").val() * 1 < x5engine.imCart.settings.minimum_amount) {
  780.             alert(x5engine.l10n.getLocalization('cart_err_minimum_price').replace(/\[PRICE\]/g, x5engine.imCart._setCurrency(x5engine.imCart.settings.minimum_amount)));
  781.             return false;
  782.         }
  783.         
  784.         obj = obj || "#imCartContainer";
  785.         obj = $(obj);
  786.         
  787.         obj.fadeOut(100, function () {
  788.             obj.empty().prepend("<h2 id=\"imPgTitle\">" + x5engine.l10n.getLocalization('cart_step3') + "</h2>\n<div style=\"height: 15px;\"> </div>");
  789.  
  790.             var html = x5engine.l10n.getLocalization('cart_step3_descr') + "<br /><br />"; 
  791.             html += "<form id=\"imCartUserDataForm\">" + x5engine.imCart.html_form + "<br />";
  792.             html += "<div style=\"text-align: center\">";
  793.             html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_goback") + "\" style=\"margin-right: 5px;\"/>";
  794.             html += "<input type=\"button\" id=\"imCartUserFormSubmit\" value=\"" + x5engine.l10n.getLocalization("cart_gonext") + "\" style=\"margin-right: 5px;\" /></form>";
  795.             html += "</div>";
  796.             
  797.             obj.append(html).fadeIn(100);
  798.             
  799.             $("#imCartButtonBack").unbind("click").click(function () { x5engine.imCart.saveForm(obj); x5engine.imCart.showCart('#' + obj.attr("id")); });
  800.             $("#imCartUserFormSubmit").unbind("click").click(function () { x5engine.imCart.showOrderSummary('#' + obj.attr("id")); });
  801.             
  802.             if (x5engine.imCart.settings.form_autocomplete) {
  803.                 var json = x5engine.imCart._getFormData();
  804.                 if (json != null) 
  805.                     for (var i = 0; i < json.length; i++)
  806.                         $("#" + json[i].id).val(json[i].val);
  807.             }
  808.         });
  809.     },
  810.     
  811.     saveForm: function (obj) {
  812.         var fields = $("#imCartUserDataForm");
  813.         var post = {};
  814.         var form = [];
  815.         $(fields).find(":input").each(function () {
  816.             if ($(this).attr("id") != null && $(this).attr("id") != "" && !$(this).is("label") && $(this).attr("type") != "submit" && $(this).attr("type") != "button" && $(this).attr("type") != "reset") {
  817.                 var fieldName = $("label[for=" + $(this).attr("id") + "] span").html();
  818.                 try {
  819.                     if (fieldName.charAt(fieldName.length - 1) == ":") fieldName = fieldName.substr(0, fieldName.length - 1);
  820.                     post[$(this).attr("id")] = {
  821.                         name: fieldName,
  822.                         imValue: ($(this).is(":checkbox") ? ($(this).prop("checked") ? "yes" : "no") : x5engine.imCart._htmlOutput($(this).val()))
  823.                     };
  824.                     form[form.length] = {
  825.                         "id": $(this).attr("id"),
  826.                         "val": ($(this).is(":checkbox") ? ($(this).prop("checked") ? "yes" : "no") : x5engine.imCart._htmlOutput($(this).val()))
  827.                     };
  828.                 } catch (e) {}
  829.             }
  830.         });
  831.  
  832.         if (x5engine.imCart.settings.form_autocomplete) 
  833.             x5engine.imCart._setFormData(form);
  834.         x5engine.imCart.email_data.form = post;
  835.     },
  836.  
  837.     // Show the order summary
  838.     showOrderSummary: function (obj) {
  839.         obj = obj || "#imCartContainer";
  840.         obj = $(obj);
  841.         if (x5engine.imForm.validate("#imCartUserDataForm", {
  842.             type: x5engine.imCart.settings.form_validation,
  843.             showAll: true,
  844.             position: "right"
  845.         })) {
  846.             obj.fadeOut(100, function () {
  847.                 var post;
  848.                 x5engine.imCart.saveForm(obj);
  849.                 post = x5engine.imCart.email_data.form;
  850.  
  851.                 obj.empty().prepend("<h2 id=\"imPgTitle\">" + x5engine.l10n.getLocalization('cart_step4') + "</h2>\n<div style=\"height: 15px;\"> </div>");
  852.                 
  853.                 // Summary
  854.                 // Products
  855.                 var html = x5engine.l10n.getLocalization('cart_step4_descr') + "<br /><br />"; 
  856.                 html += "<table id=\"imCartProductsTable\"><tr class=\"imCartHeader\">";
  857.                 html += "<td style=\"width: " + (x5engine.imCart.settings.vatincluded ? "48" : "35") + "%\">" + x5engine.l10n.getLocalization("cart_descr") + "</td>";
  858.                 html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_opt") + "</td>";
  859.                 html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_qty") + "</td>";
  860.                 html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_price") + "</td>";
  861.                 if (!x5engine.imCart.settings.vatincluded)
  862.                     html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_vat") + "</td>";
  863.                 html += "<td style=\"width: 13%\">" + x5engine.l10n.getLocalization("cart_subtot") + "</td></tr>";
  864.  
  865.                 var data = x5engine.imCart.email_data;
  866.  
  867.                 for (var product in data.products) {
  868.                     html += "<tr valign=\"top\"><td>" + data.products[product].name + (data.products[product].description != "" ? " - " + data.products[product].description : "") + "</td>";
  869.                     html += "<td>" + ((data.products[product].option != "null") ? x5engine.imCart._restoreSpecialChars(unescape(data.products[product].option)) : "") + "</td>";
  870.                     html += "<td style=\"text-align: right;\">" + data.products[product].quantity + "</td>";
  871.                     html += "<td style=\"text-align: right;\">" + data.products[product].single_price + "</td>";
  872.                     if (!x5engine.imCart.settings.vatincluded)
  873.                         html += "<td style=\"text-align: right;\">" + ((data.products[product].vat != null && data.products[product].vat > 0) ? ((data.products[product].vat * 100).toFixed(2) + "% / " + data.products[product].vat_f) : "-") + "</td>";
  874.                     html += "<td style=\"text-align: right;\">" + data.products[product].price_vat + "</td></tr>";
  875.                 }
  876.                 html += "</table>";
  877.  
  878.                 // Payment
  879.                 var payment = x5engine.imCart.payments[x5engine.imCart._getPayment()]
  880.                 html += "<br /><table id=\"imCartPaymentsTable\" style=\"width: 74%\">";
  881.                 html += "<tr class=\"imCartHeader\"><td>" + x5engine.l10n.getLocalization("cart_payment") + "</td>" + ((x5engine.imCart.email_data.payment.price != null) ? "<td>" + x5engine.l10n.getLocalization("cart_price") + "</td>" : "") + "</tr>";
  882.                 html += "<tr valign=\"top\"><td style=\"width: 85%\"><b>" + payment.name + "</b><br />" + payment.description + "</td>" + ((x5engine.imCart.email_data.payment.price != null) ? "<td style=\"width: 15%; text-align: right;\">" + x5engine.imCart.email_data.payment.price + "</td>" : "") + "</tr></table>";
  883.                 
  884.                 // Shipping
  885.                 var shippig = x5engine.imCart.shippings[x5engine.imCart._getShipping()]
  886.                 html += "<br /><table id=\"imCartShippingsTable\" style=\"width: 74%\">";
  887.                 html += "<tr class=\"imCartHeader\"><td style=\"width: 85%\">" + x5engine.l10n.getLocalization("cart_shipping") + "</td>" + ((x5engine.imCart.email_data.shipping.price != null) ? "<td style=\"width: 15%\">" + x5engine.l10n.getLocalization("cart_price") + "</td>" : "") + "</tr>";
  888.                 html += "<tr valign=\"top\"><td><b>" + shippig.name + "</b><br />" + shippig.description;
  889.                 html += "<br /><br /><b>" + x5engine.l10n.getLocalization("cart_shipping_address") + ":</b><br />";
  890.                 if (post["imCartName_shipping"] != null) {
  891.                     html += ((post["imCartCompany_shipping"] != null && post["imCartCompany_shipping"] != "") ? post["imCartCompany_shipping"].imValue + " - " : "");
  892.                     html += ((post["imCartName_shipping"] != null) ? post["imCartName_shipping"].imValue + " " : "");
  893.                     html += ((post["imCartLastName_shipping"] != null) ? post["imCartLastName_shipping"].imValue : "");
  894.                     html += " " + ((post["imCartEmail_shipping"] != null) ? ("(" + post["imCartEmail_shipping"].imValue + ")") : "") + "<br />";
  895.                     html += ((post["imCartAddress1_shipping"] != null) ? (post["imCartAddress1_shipping"].imValue + "<br />") : "");
  896.                     html += ((post["imCartAddress2_shipping"] != null) ? (post["imCartAddress2_shipping"].imValue + "<br />") : "");
  897.                     html += ((post["imCartCity_shipping"] != null) ? (post["imCartCity_shipping"].imValue) : "");
  898.                     html += ((post["imCartStateRegion_shipping"] != null) ? (" (" + post["imCartStateRegion_shipping"].imValue + ")") : "");
  899.                     html += ((post["imCartZipPostalCode_shipping"] != null) ? (", " + post["imCartZipPostalCode_shipping"].imValue + "<br />") : "");
  900.                     html += ((post["imCartCountry_shipping"] != null) ? (post["imCartCountry_shipping"].imValue + "<br />") : "");
  901.                 } else if (post["imCartName"] != null) {
  902.                     html += ((post["imCartCompany"] != null && post["imCartCompany"] != "") ? post["imCartCompany"].imValue + " - " : "");
  903.                     html += ((post["imCartName"] != null) ? post["imCartName"].imValue + " " : "");
  904.                     html += ((post["imCartLastName"] != null) ? post["imCartLastName"].imValue : "");
  905.                     html += " " + ((post["imCartEmail"] != null) ? ("(" + post["imCartEmail"].imValue + ")") : "") + "<br />";
  906.                     html += ((post["imCartAddress1"] != null) ? (post["imCartAddress1"].imValue + "<br />") : "");
  907.                     html += ((post["imCartAddress2"] != null) ? (post["imCartAddress2"].imValue + "<br />") : "");
  908.                     html += ((post["imCartCity"] != null) ? (post["imCartCity"].imValue) : "");
  909.                     html += ((post["imCartStateRegion"] != null) ? (" (" + post["imCartStateRegion"].imValue + ")") : "");
  910.                     html += ((post["imCartZipPostalCode"] != null) ? (", " + post["imCartZipPostalCode"].imValue + "<br />") : "");
  911.                     html += ((post["imCartCountry"] != null) ? (post["imCartCountry"].imValue + "<br />") : "");
  912.                 }
  913.                 html += "</td>" + ((x5engine.imCart.email_data.shipping.price != null) ? "<td style=\"text-align: right\">" + x5engine.imCart.email_data.shipping.price + "</td>" : "") + "</tr></table>";
  914.  
  915.                 // Total
  916.                 html += "<div><div id=\"imCartTotalPriceCont\">" + x5engine.l10n.getLocalization('cart_total_price') + ": <span id=\"imDivTotalPrice\">" + x5engine.imCart.email_data.total + "</span></div></div>";
  917.  
  918.                 // Next/Previous button
  919.                 html += "<br /><br /><br />";
  920.                 html += "<div style=\"text-align: center; clear: both; margin-top: 30px;\">";
  921.                 html += "<input type=\"button\" id=\"imCartButtonBack\" value=\"" + x5engine.l10n.getLocalization("cart_goback") + "\" style=\"margin-right: 5px;\" />";
  922.                 html += "<input type=\"button\" id=\"imCartUserFormSubmit\" value=\"" + x5engine.l10n.getLocalization("cart_gonext") + "\" style=\"margin-left: 5px;\" />";
  923.                 html += "</html>";
  924.  
  925.                 obj.append(html).fadeIn(100);
  926.                 
  927.                 $("#imCartButtonBack").unbind("click").click(function () { x5engine.imCart.showForm('#' + obj.attr("id")); });
  928.                 $("#imCartUserFormSubmit").unbind("click").click(function () { x5engine.imCart.sendOrderEmail('#' + obj.attr("id")); });
  929.             });
  930.  
  931.         } else $("#imCartUserFormSubmit").attr("disabled", false);
  932.     },
  933.  
  934.     // Send the email and shows the payment
  935.     sendOrderEmail: function (obj) {
  936.         $("#imCartUserFormSubmit").attr("disabled", true);
  937.         if (x5engine.imCart.email_data.order_no == null || x5engine.imCart.email_data.order_no == "")
  938.             x5engine.imCart.email_data.order_no = x5engine.imCart._createOrderNo();
  939.         var pid = x5engine.imCart._getPayment();
  940.         if (x5engine.imCart.payments[pid].html != null)
  941.             x5engine.imCart.email_data.payment.html = x5engine.imCart._createPaymentHtml(x5engine.imCart.payments[pid].html);
  942.         if (x5engine.utils.isOnline()) {
  943.             $("#imCartUserFormSubmit").val(x5engine.l10n.getLocalization('cart_order_process')).css({ cursor: "wait" });
  944.             $("#imCartButtonBack").remove();
  945.             $.ajax({
  946.                 type: "POST",
  947.                 url: x5engine.imCart.settings.post_url,
  948.                 data: x5engine.imCart.email_data,
  949.                 success: function (a) {
  950.                     x5engine.imCart.showPayment(obj);
  951.                 },
  952.                 error: function (XMLHttpRequest, textStatus, errorThrown) {
  953.                     x5engine.imCart.showPayment(obj);
  954.                 }
  955.             });
  956.         } else {
  957.             x5engine.utils.showOfflineMessage(x5engine.l10n.getLocalization('cart_err_offline_email').replace(/\[MAIL\]/g, x5engine.imCart.email_data.form.imCartEmail.imValue)); 
  958.             x5engine.imCart.showPayment(obj);
  959.         }
  960.     },
  961.  
  962.     // Shows the payment method
  963.     showPayment: function (obj) {
  964.         var payment = x5engine.imCart.payments[x5engine.imCart._getPayment()];
  965.         $(obj).empty().prepend("<h2 id=\"imPgTitle\">" + x5engine.l10n.getLocalization('cart_step5') + "</h2>\n<div style=\"height: 15px;\"> </div>");
  966.         var html = x5engine.l10n.getLocalization('cart_step5_descr') + "<br /><br />"; 
  967.         html += "<div id=\"imCartOrderNumber\">" + x5engine.imCart.email_data.order_no + "</div>";
  968.         html += "<h3>" + payment.name + "</h3>" + payment.description + "<br /><br />";
  969.         html += payment.email;
  970.         
  971.         if (payment.html != null) {
  972.             html += "<br /><br /><div style=\"text-align: center\">" + x5engine.imCart._createPaymentHtml(payment.html) + "</div>";
  973.         }
  974.  
  975.         $(obj).fadeOut(100, function () {
  976.             $(obj).append(html).fadeIn(100, function () {
  977.                 x5engine.imCart.emptyCart(false);
  978.                 x5engine.imCart.email_data = null;
  979.                 x5engine.imCart._setShipping(null);
  980.                 x5engine.imCart._setPayment(null);
  981.             });
  982.         });
  983.     },
  984.  
  985.     // Update the shipping type and price
  986.     updateShipping: function (n, total_quantity, total_weight) {
  987.         x5engine.imCart._setShipping(n);
  988.         x5engine.imCart.updateTotalPrice(total_quantity, total_weight);
  989.     },
  990.  
  991.     // Update the payment type and the price
  992.     updatePayment: function (n, total_quantity, total_weight) {
  993.         x5engine.imCart._setPayment(n);
  994.         x5engine.imCart.updateTotalPrice(total_quantity, total_weight);
  995.     },
  996.  
  997.     // Update the total price
  998.     updateTotalPrice: function (total_quantity, total_weight) {
  999.         var price = x5engine.imCart.product_price_plus_vat;
  1000.         var pid;
  1001.         var sid;
  1002.         var shipping_price = 0;
  1003.         var payment_price = 0;
  1004.         x5engine.imCart.email_data.total_quantity = total_quantity;
  1005.         x5engine.imCart.email_data.total_weight = total_weight;
  1006.         if (x5engine.imCart._getShipping() != null) {
  1007.             sid = x5engine.imCart._getShipping();
  1008.             shipping_price += x5engine.imCart._getShippingPrice(x5engine.imCart.shippings[sid], x5engine.imCart.product_price_plus_vat, total_quantity, total_weight) * 1;
  1009.             x5engine.imCart.email_data.shipping = {
  1010.                 id: sid,
  1011.                 price: x5engine.imCart._setCurrency(shipping_price),
  1012.                 name: x5engine.imCart.shippings[sid].name,
  1013.                 description: x5engine.imCart.shippings[sid].description,
  1014.                 email: x5engine.imCart.shippings[sid].email
  1015.             }
  1016.             if (shipping_price == 0) {
  1017.                 x5engine.imCart.email_data.shipping.price = null;
  1018.             }
  1019.         }
  1020.         if (x5engine.imCart._getPayment() != null) {
  1021.             pid = x5engine.imCart._getPayment();
  1022.             if (x5engine.imCart.payments[pid].price != null) {
  1023.                 payment_price += x5engine.imCart.payments[pid].price;
  1024.                 if (x5engine.imCart.payments[pid].vat != null) payment_price += x5engine.imCart.payments[pid].price * x5engine.imCart.payments[pid].vat;
  1025.             }
  1026.             x5engine.imCart.email_data.payment = {
  1027.                 id: pid,
  1028.                 price: x5engine.imCart._setCurrency(payment_price),
  1029.                 name: x5engine.imCart.payments[pid].name,
  1030.                 description: x5engine.imCart.payments[pid].description,
  1031.                 email: x5engine.imCart.payments[pid].email
  1032.             };
  1033.             if (x5engine.imCart.payments[pid].html != null)
  1034.                 x5engine.imCart.email_data.payment.html = x5engine.imCart._createPaymentHtml(x5engine.imCart.payments[pid].html);
  1035.             if (payment_price == 0) {
  1036.                 x5engine.imCart.email_data.payment.price = null;
  1037.             }
  1038.         }
  1039.         price += shipping_price + payment_price;
  1040.         x5engine.imCart.email_data.total = x5engine.imCart._setCurrency(price);
  1041.         x5engine.imCart.email_data.clear_total = price;
  1042.         $("#imDivTotalPrice").html(x5engine.imCart._setCurrency(price));
  1043.         x5engine.imCart.total_price = price;
  1044.     }
  1045. });